package com.lagou.homework;

import java.sql.*;

public class TestJDBCUtils {
        // 需求 根据name 和 gender 进行数据查询
    public static void main(String[] args) throws SQLException {

        // 1.建立连接获取连接对象
        Connection connection = JDBCUtils.getConnection();
        // 2.获取执行SQL语句对象
        String sql = "select * from employee where name = ? ";
        PreparedStatement ps = connection.prepareStatement(sql);
        ps.setString(1,"奇点");
        // 3.执行SQL语句
        ResultSet resultSet = ps.executeQuery();
        // 4.结果集处理
        while (resultSet.next()) {
            int id = resultSet.getInt("id");
            String gender = resultSet.getString("gender");
            String name = resultSet.getString("name");
            double salary = resultSet.getDouble("salary");
            double bonus = resultSet.getDouble("bonus");
            Date join_date = resultSet.getDate("join_date");
            System.out.println("id = " + id + "name = " + name + "salary = " + salary + "bonus" + bonus + "join_date" + join_date );
        }
        // 5.释放资源
        JDBCUtils.close(connection,ps,resultSet);
    }
}
